package com.yonyou.iuap.jxzy.service;


import com.yonyou.iuap.baseservice.intg.service.GenericIntegrateService;
import com.yonyou.iuap.baseservice.intg.support.ServiceFeature;
import com.yonyou.iuap.jxzy.dao.RegisterMapper;
import com.yonyou.iuap.jxzy.entity.User;
import com.yonyou.uap.ieop.security.exception.BusinessException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @program: jxProject
 * @description: 用户登录和修改密码，修改预约密码
 * @author: Pengjx
 * @create: 2019-05-24 13:56
 **/
@Service
//extends GenericIntegrateService<User>
public class RegisterService extends GenericIntegrateService<User> {



    @Autowired
    private RegisterMapper mapper;

    public  User findByUser(String name,String password,String isApp)throws Exception{
    	User user=null;
    	if(mapper.findUserexit(name)==null){
    		throw new BusinessException("没有查询到该客户");
    	}
    	if("N".equals(isApp)){
    		user=mapper.getUser(name,password);
    	}else{
    		user=mapper.getUserApp(name,password);
    	}
    	
    	if (user==null) {
    		throw new BusinessException("密码错误");
		}
    	 return  user;
	
    }



    public  Integer updateUserByName(String name,String password,String isApp){
    	Integer num=null;
    	if("N".equals(isApp)){
    		num=mapper.updateUserByName(name,password);
    	}else{
    		num=mapper.updateUserByNameApp(name,password);
    	}
        //根据密码返回不同的结果
        if (num<=0){
            System.out.println("============");
        }
        return  num;

    }

    @Override
    protected ServiceFeature[] getFeats() {
        return new ServiceFeature[0];
    }



	public Integer updateOrderPasswordByName(String name, String orderpassword) {
		StringBuffer erreyMsg = new StringBuffer();
		try {
			Integer num=mapper.updateOrderPasswordByName(name,orderpassword);
			if (num==0) {
				throw new NullPointerException("没有找到该客户,预约密码更新失败!");
			}
			return num;
		} catch (Exception e) {
			erreyMsg.append("该客户"+name+"没有找到"+orderpassword+"更新失败"+e.getMessage());
		}
		return null;
		
	}
	
	public String getRes(String name){
		String res = mapper.getRes(name);
		if(!StringUtils.isEmpty(res)){
			return mapper.getRes(name);
		}
		return "";
	}
}
